#include "Pch.h"

#include <iostream>
#include <Ishtar/Application.h>
#include <Ishtar/Application/ProgramOptions.h>
#include <Ishtar/Thread/ThreadGroup.h>
#include "TestCase.h"
 
using namespace std;
using namespace Ishtar;


ProgramOptionUint s_testNo( "t", 0 );
 
class MyApp : public ConsoleApplication
{
private:
    Int DoRun();
    
    boost::scoped_ptr< TestCase > m_test;

    ThreadGroup m_threads;
};
 
Int MyApp::DoRun()
{
    switch ( s_testNo )
    {
    case 0:
        m_test.reset( new CommitRateTest );
        break;
    
    default:
        cout << "Unknown test number : " << s_testNo << endl;
        cin.get();
        return EXIT_FAILURE;
    }

    cout << "Start " << m_test->GetName() << " Test" << endl;

    m_threads.AddOnceThread(
        m_test->GetName(), boost::bind( &TestCase::Run, m_test.get() ));

    while ( !m_test->IsStopped() )
    {
        const Int key = this->TimedWaitKeyboard( 1 );
        if ( 0 != key )
        {
            m_test->Stop();
            break;
        }
    }

    m_threads.Shutdown();

    cout << "Test stopped, program now exits" << endl;
    cin.get();

    return EXIT_SUCCESS;
}
 
int main()
{
    MyApp app;
    return app.Run();
}
